﻿using System.Diagnostics;

namespace SharpObjects.Logging.Utils
{
    public static class ProcessInformation
    {
        public static bool UseProcessInfo { get; set; }

        private static string processName = string.Empty;
        private static int processId = -1;


        static ProcessInformation()
        {
            UseProcessInfo = true;   
        }

        public static string ProcessName
        {
            get
            {
                if (UseProcessInfo)
                {
                    if (processId == -1)
                    {
                        processId = Process.GetCurrentProcess().Id;
                    }

                    if(processName == string.Empty)
                    {
                        processName = Process.GetCurrentProcess().ProcessName;
                    }

                    return processName;
                }
                else
                {
                    return string.Empty;
                }
            }
            set
            {
                processName = value;
            }
        }

        public static int ProcessId
        {
            get
            {
                if (UseProcessInfo)
                {
                    if (processId == -1)
                    {
                        processId = Process.GetCurrentProcess().Id;
                    }

                    if (processName == string.Empty)
                    {
                        processName = Process.GetCurrentProcess().ProcessName;
                    }

                    return processId;
                }
                else
                {
                    return -1;
                }
            }
        }
    }
}
